const Loader = require('wy-Loader');
cc.Class({
    extends: require('wy-Component'),

    properties: {
        _options: {
            default: {}
        },
        alertNode: cc.Node,
        alertFont: cc.Label,
    },

    onLoad: function () {
        this.panel = Loader.getInstantiate('./UI/UI-Panel');
        this.node.addChild(this.panel);
        this.okButton = Loader.getInstantiate('./UI/UI-TextButton');
        this.alertNode.addChild(this.okButton);
        this._options = {
            message: '这是一个警告框',
            title: '警告',
            okButtonText: "确认",
            okButtonCallback: () => { }
        }
    },

    start: function () {

    },

    setOptions: function (data) {
        Object.assign(this._options, data)
        this.alertFont.string = data.message;
        let oKButtonOptions = {
            x: 0, y: -100,
            width: 160,
            height: 60,
            btnColor: 'red',
            textColor: 'black',
            text: this._options.okButtonText,
            tapCallback: () => {
                this._options.okButtonCallback();
                this.node.destroy();
            },
        }
        this.okButton.js.setOptions(oKButtonOptions);
        let panelObj = {
            x: 0, y: 0,
            width: 600,
            height: 350,
            isClose: false,
            isModel: true,
            isModelClose: false,
            content: this.alertNode,
            titleText: this._options.title,
        };
        this.panel.js.setOptions(panelObj);
    },
    // update (dt) {},
});
